var PeopleMedia = PeopleMedia || {};

PeopleMedia.InternalHeader = (function ($jq) {

    var toggleChat = function () {
        if (PMChat.ChatEnabled) {
            PMChat.SetOnlineStatus(0, PeopleMedia.InternalHeader.toggleChatComplete);
        } else {
            PMChat.SetOnlineStatus(1, PeopleMedia.InternalHeader.toggleChatComplete);
        }
    };

    var toggleChatComplete = function () {
        var $toolBar = $jq(document.getElementById('NotificationsToolbar'));

        if (PMChat.ChatEnabled) {
            $jq("#usernameMenuChatStatusText").text("Turn Chat Off");
            $jq("#usernameMenuChatStatusText").parent().show();

            if ($toolBar != null) {
                $toolBar.find('div.btnChat > img:first-child').attr('src', PeopleMedia.SiteImagePath + '/images/notificationstoolbar/chatonicon.png');
                $toolBar.find('div.btnChat > img:first-child').attr('title', 'You are Online and can send and receive chats. Click to go Offline.');
                $toolBar.find('div.btnChat > span > img[title]').attr('title', '');
                $toolBar.find('div.btnChat > span > div[title]').attr('title', '');
                PeopleMedia.NotificationsToolbar.SetOnlineCount();
            }
        } else {
            $jq("#usernameMenuChatStatusText").text("Turn Chat On");
            $jq("#usernameMenuChatStatusText").parent().show();

            if ($toolBar != null) {
                $toolTip = "You are Offline and cannot send or receive chats.  Click to go Online.";
                $toolBar.find('div.btnChat > img:first-child').attr('src', PeopleMedia.SiteImagePath + '/images/notificationstoolbar/chatofficon.png');
                $toolBar.find('div.btnChat > img:first-child').attr('title', $toolTip);
                $toolBar.find('div.btnChat > span > img[title]').attr('title', $toolTip);
                $toolBar.find('div.btnChat > span > div[title]').attr('title', $toolTip);
                $toolBar.find('span[data-online-label]').html('Off');
            }
        }
    };

    return {
        toggleChat: toggleChat,
        toggleChatComplete: toggleChatComplete
    };
})(jQuery);
